//
//  CommentsViewController.m
//  GuideMe
//
//  Created by Amila Fonseka on 3/24/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "CommentsViewController.h"

@implementation CommentsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        arrComments = [[NSMutableArray alloc] initWithArray:[NSArray arrayWithObjects:
                                    NSLocalizedString(@"Nice Place to go", @""),
                                    NSLocalizedString(@"Guys check out the X location on your way, it really is awesome", @""),
                                    NSLocalizedString(@"Meet the Thambili Shop near Cottage Y", @""),
                                    NSLocalizedString(@"This tour was totally crazy...!!!", @""),
                                    nil]];
    }
    return self;
}

- (IBAction)btnBackTapped
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)btnAddCommentTapped
{
    [txtComment resignFirstResponder];
    
    if ([txtComment.text length] > 0)
    {
        [arrComments addObject:NSLocalizedString(txtComment.text, @"")];
        [tblComments reloadData];
        txtComment.text = @"";
        
    }
    else
    {
        UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Comment Error" message:@"Sorry, comment is empty." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
        [errorAlert release];
    }
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tabelView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 40.0;
}

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	if(section==0)
    {
        if ([arrComments count] > 0)
        {
            return [arrComments count];
        }
        return 0;
    }
	
	return 0;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{	
	static NSString *EmptyCellIdentifier = @"EmptyCell";
	
	UITableViewCell *emptyCell = [tableView dequeueReusableCellWithIdentifier:EmptyCellIdentifier];
	if (emptyCell == nil)
	{
		emptyCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:EmptyCellIdentifier] autorelease];   
		emptyCell.detailTextLabel.textAlignment = UITextAlignmentLeft;
		emptyCell.selectionStyle = UITableViewCellSelectionStyleNone;
	}
    
	if ([arrComments count] > 0)
    {
        emptyCell.detailTextLabel.frame = CGRectMake(20.0, 10.0, 280.0, 20.0);
        emptyCell.contentView.backgroundColor = [UIColor whiteColor];
        emptyCell.detailTextLabel.textColor = [UIColor blackColor];
        emptyCell.detailTextLabel.text = [arrComments objectAtIndex:indexPath.row];
        return emptyCell;
    }
    else
    {
        emptyCell.detailTextLabel.frame = CGRectMake(20.0, 10.0, 280.0, 20.0);
        emptyCell.contentView.backgroundColor = [UIColor whiteColor];
        emptyCell.detailTextLabel.text = @"Sorry there are no tours at the moment";
        return emptyCell;
    }
    return emptyCell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}


#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
